package com.hengtiansoft.lfy.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.hengtiansoft.lfy.R;

/**
 * Created by daiye on 2016/10/25 0025.
 */

public class CDeleteDialog extends Dialog implements View.OnClickListener {
    private Context context;
    private OnItemClick mListener = null;

    public CDeleteDialog(Context context) {
        super(context, R.style.DialogCustom);
        this.context = context;
    }

    @Override
    protected final void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_delete);

        // findViewById(R.id.tips_tv).setOnClickListener(this);
        findViewById(R.id.delete_tv).setOnClickListener(this);
        findViewById(R.id.button_cancel).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.delete_tv:
                if(mListener!=null)
                    mListener.onItemClick(1);
                break;
            case R.id.button_cancel:
                this.dismiss();
                break;
            default:
                break;
        }
        new android.os.Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (null != CDeleteDialog.this && CDeleteDialog.this.isShowing()) {
                    CDeleteDialog.this.dismiss();
                }
            }
        }, 100);
    }

    @Override
    public void setTitle(CharSequence title) {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public void show() {
        if (context != null && ((Activity)context).isFinishing()) {
            return;
        }
        super.show();
    }

    public void setItemClickListener( OnItemClick p){
        mListener = p;
    }

    public interface OnItemClick {
        public void onItemClick(int position);
    }
}